# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Felix Kaiser <felix.kaiser@fxkr.net>

pkgbase=python-pytest
pkgname=('python3-pytest' 'python2-pytest')
pkgver=3.2.1
pkgrel=1
pkgdesc="Simple powerful testing with Python"
arch=('any')
license=('MIT')
url="https://pytest.org/"
makedepends=('python3-setuptools' 'python2-setuptools' 'python3-setuptools-scm' 'python2-setuptools-scm' 'python3-py' 'python2-py')
source=("https://pypi.python.org/packages/source/p/pytest/pytest-$pkgver.tar.gz")
sha512sums=('e0fff27fbf8fb79015520f338a418ad0c50ce75e8438e916ae40b1e2c2ad423b7629a9c7e08387b95eddd805f9887175c3159574b0b4c418c7bc9811c10fa7b9')

prepare() {
  sed -i "s/'_pytest.vendored_packages'//" pytest-${pkgver}/setup.py
  sed -i 's/assert numentries == 0/assert numentries == 26/' pytest-${pkgver}/testing/python/collect.py
  cp -a pytest-${pkgver}{,-py2}
}

build() {
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
  
  cd "${srcdir}/pytest-${pkgver}"
  python3 setup.py build

  cd "${srcdir}/pytest-${pkgver}-py2"
  python2 setup.py build
}

package_python3-pytest() {
  depends=('python3' 'python3-py' 'python3-setuptools')

  cd pytest-${pkgver}
  python3 setup.py install --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_python2-pytest() {
  depends=('python2' 'python2-py' 'python2-setuptools')

  cd pytest-${pkgver}-py2
  python2 setup.py install --root="${pkgdir}" --optimize=1
  install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

  for f in {py.test,pytest}; do
    mv "${pkgdir}"/usr/bin/${f}{,2}
  done
}

